<?php
require_once 'includes/classes/SmsSender.php';

$phone = $_POST['phone'];
$success = false;
$error = "验证码发送失败";
try {
    $appid = 1400026314;
    $appkey = "d430940aeb971d2e33571aaa7b519cfa";
    $templId = 12617;
    $singleSender = new SmsSingleSender($appid, $appkey);
    $code = rand(1000, 9999);
    $_SESSION['smscode'] = $code;
    $params = [ "{$code}", "2"];
    $result = $singleSender->sendWithParam("86", $phone, $templId, $params, "澳睿跑教育集团");
    $rsp = json_decode($result, true);
    if ($rsp['result'] === 0) {
        $success = true;
        $error = null;
    } else {
        $error = $rsp['errmsg'];
    }
} catch (Exception $e) {
}
echo json_encode(['success'=>$success, 'error'=>$error]);
die();
